import { proxy } from "valtio";
import { getMerchantList } from "@/pages/merchant/api/merchant"
import { getShopList } from "@/pages/merchant/api/shop"
import { getPartitionList } from "@/pages/merchant/api/partition"
import { getBrandList } from "@/pages/merchant/api/brand"
import {getBindList} from "@/pages/merchant/api/bind"
import { getPrinterList } from "@/pages/merchant/api/printer"


export const state = proxy({
    merchantList: [],
    brandList: [],
    printerList:[],
    shopList: [],
    areaList: [],
    areaCate: [],
    brandCate: [],
    shopCate: [],
    bindList:[],
    shopName:"",

    //重新设置商户名称
    setShopName: (name: string) => {
        state.shopName = name;
    },

    // 获取商户
    getData: async (data:any) => {
        await getMerchantList(data).then((res:any)=>{
            state.merchantList = res.data.map((item: any, index: any) => ({ ...item, key: index + 1 }));
        })
    },
    // 获取品牌
    getData2: async (data: any) => {
        await getBrandList(data).then((res: any) => {
            state.brandList =   res.data.map((item: any, index: any) => ({ ...item, key: index + 1 }));
        })
    },
    // 获取店铺
    getData3: async (data: any) => {
        await getShopList(data).then((res: any) => {
            state.shopList = res.data.map((item: any, index: any) => ({ ...item, key: index + 1 }));
        })
    },
    // 获取分区
    getData4: async (data: any) => {
        await getPartitionList(data).then((res: any) => {
            state.areaList = res.data.map((item: any, index: any) => ({ ...item, key: index + 1 }));
        })
    },
    // 获取绑定店铺
    getData6: async (data: any) => {
        console.log(data, "777777");
        await getBindList(data).then((res: any) => {
    

            state.bindList = res.data.map((item: any, index: any) => ({ ...item, key: index + 1 }));
        })
    },
    // 获取绑定打印机
    getData7: async (data: any) => {
        await getPrinterList(data).then((res: any) => {
            state.printerList = res.data.map((item: any, index: any) => ({ ...item, key: index + 1 }));
        })
    },
    //获取分类
    getData5: async () => {
        await getBrandList({}).then((res: any) => {
            state.brandCate = res.brandNameList
        })
        await getPartitionList({}).then((res: any) => {
        

            state.areaCate = res.areaNameList
        })
        await getShopList({}).then((res: any) => {
            state.shopCate = res.shopCate
        })
    }

});
